package com.mworld.galaxy.bull.repository.product;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import com.mworld.galaxy.bull.entity.product.Category;

public interface CategoryDao extends PagingAndSortingRepository<Category, Long>, JpaSpecificationExecutor<Category> {
    Category findByName(String name);

    @Modifying
    @Query("UPDATE Category c SET c.status = ?2 WHERE c.id = ?1")
    void changeStatus(Long id, int status);

    @Modifying
    @Query("UPDATE Category c SET c.status = ?2 WHERE c.level2Id = ?1")
    void changeStatusFromLevel2(Long id, int status);

    @Modifying
    @Query("UPDATE Category c SET c.status = ?2 WHERE c.level1Id = ?1")
    void changeStatusFromLevel1(Long id, int status);
}
